package com.rw.coco.handler.message.reply.handler.validate;

import com.rw.coco.handler.message.event.CocoGroupMessageEvent;
import com.rw.coco.handler.message.event.CocoMessageEvent;
import com.rw.coco.handler.message.reply.ReplyHandler;

/**
 * 黑名单校验过滤器
 */
public class BlackListFilter implements ReplyHandler {
    @Override
    public boolean trigger(CocoMessageEvent cocoMessageEvent) {
        // 如果用户在黑名单内，则拦截
        if (cocoMessageEvent.getAccountModel().isBlackList()) {
            return true;
        }

        // 如果是群组对话
        if (cocoMessageEvent instanceof CocoGroupMessageEvent) {
            CocoGroupMessageEvent groupMessageEvent = (CocoGroupMessageEvent) cocoMessageEvent;

            // 如果群组在黑名单中，则拦截
            return groupMessageEvent.getGroupModel().isBlackList();
        }

        return false;
    }

    @Override
    public void handler(CocoMessageEvent cocoMessageEvent) {
    }
}
